<%@ page contentType="text/html;charset=UTF-8"%>
<%@ include file="/common/taglibs.jsp"%>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta name="menu" content="assetMenu" />
<meta name="nav" content="1" />
<meta name="acc" content="0-2-0" />
<title>图书管理</title>
<!--  通用情况下 不引入 js css  表单验证  js 放置到页面中 -->
<script>
	$(document).ready(function() {
		 $("input[name='publicationDate']").addClass("Wate").bind("click", function(){
   	     WdatePicker({skin:'whyGreen',minDate:'1990-01-01',maxDate:'%y-%M-%d',dateFmt:'yyyy-MM-dd'});});
		 $("input[name='effectiveDate']").addClass("Wate").bind("click", function(){
	   	    WdatePicker({skin:'whyGreen',minDate:'1990-01-01',maxDate:'%y-%M-%d',dateFmt:'yyyy-MM-dd'});});
		 $("#bookName").focus();
			//为inputForm注册validate函数
		 $("#inputForm").validate({
			 	rules: {
			 			bookNo:{
						  		required: true,
						remote: "information!checkNo.action?oldBookNo=${bookNo}&"
						},
						sindex:{
							required:true,
							remote: "information!checkSindex.action?oldSindex=${sindex}&"
						},
						publisher:{
							required: true,
						}
				},
	
				messages: {
					bookNo: {
						required: "必须填写图书编号！",
						remote:"该编号已被使用！"
					},
					sindex:{
						number:"请输入上架号！"
					}
				}
			});
		});
		
		count = ${fn:length(bksnList)};
		function doAppend() { 
			count++;
			var  content = '<tr id="snTr${status.count}">'+
			'<td>图书ISBN编号</td>'+
			'<td><input id="bkSn'+count+'" name="bookSN" type="text" />'+
			'<input id="bkid'+count+'" name="id" type="hidden" />'+
			'<input id="bookinfoId'+count+'" name="bookinfoId'+count+'" type="hidden" value="${id}" />'+
			'<input id="status${'+count+'}" name="status" type="hidden"  /> ' +
			'</td> <td colspan="2">'+
			'<input id="savebksn" type="button" class="submit"  value="保存"  onclick="saveBkSn('+count+');"/> '+
			' <input align="bottom" type="button" class="reset" value="删除" onclick="deleteBkSn('+count+');"/></td></tr>';
			$("#tabtest").append(content);
		} 

		function deleteBkSn(param){
			var bookId = $("#bkid"+param).val();
			var bkstatus =$("#status"+param).val();
			if(bkstatus=="1"){
				alert("本书已借出,不能执行此操作!");
				return;
			}
			var url = '${ctx}/asset/book/bksn!delete.action';
			$.post( url,{bkid:bookId}, function(msg){
				if("1"==msg){
					if ($.browser.msie) {
						alert("删除成功!");																    		   
		    		}else{
		    			alert("删除成功!");											
		    		}
					$("#snTr"+param).remove();
				}else{
					alert("系统出错!");
				}
			},"text");				
		}
		
		function saveBkSn(param){
			var bookSn = $("#bkSn"+param).val();
			var bookId = $("#bkid"+param).val();
			var bookinfoId = $("#bookinfoId"+param).val();
			var url = "${ctx}/asset/book/bksn!save.action";
			$.post( url,{bkSn:bookSn ,bkid:bookId,bookinfoId:bookinfoId}, function(msg){
				if("1"==msg){
					if ($.browser.msie) {
						alert("保存成功!");																    		   
		    		}else{
		    			alert("保存成功!");										
		    		}
				}else{
					alert("系统出错!");
				}
			},"text");	
		}
		
	</script>
</head>
<body>
<form action="${ctx }/asset/book/information!save.action" method="post"
	id="inputForm" class='yform'>
<div id="caption">
<h6>${bookName}图书管理</h6>
</div>
<table class="noborder">
	<tr class="type-title">
	</tr>
	<tr class="type-text">
		<td>图书名称</td>
		<td><input id="bookId" name="id" type="hidden" value="${id}" />
		<input id="bookName" name="bookName" type="text" value="${bookName}" /></td>
		<td>图书类型</td>
		<td><pt:code name="bookType" prompt="全部" category="2023" hasEmpty="false"
			default="${bookType}"></pt:code></td>
	</tr>
	<tr class="type-text">
		<td>图书编号</td>
		<td><input type="text" id="bookNo" name="bookNo"
			value="${bookNo}" /></td>
		<td>上架号</td>
		<td><input type="text" id="sindex" name="sindex"
			value="${sindex}" /></td>
	</tr>
	<tr class="type-select">
		<td>作者</td>
		<td class="type-text"><input id="edit" type="text" name="edit"
			value="${edit}" /></td>
		<td>存放地</td>
		<td><input id="stored" type="text" name="stored"
			value="${stored}" /></td>
	</tr>
	<tr class="type-text">
		<td>部门选择</td>
		<td><pt:labels type="insideOrgDept" name="DEPTID"
			default="${department.id}">
		</pt:labels></td>
		<td>出版社</td>
		<td><input type="text" id="publisher" name="publisher"
			value="${publisher}" /></td>
	</tr>
	<tr class="type-text">
		<td>实施时间</td>
		<td><input type="text" name="effectiveDate"
			value="${effectiveDate}" readonly="readonly" /></td>
		<td>出版时间</td>
		<td><input type="text" name="publicationDate"
			value="${publicationDate}" readonly="readonly" /></td>
	</tr>
	<tr class="type-text">
		<td>内容简介</td>
		<td colspan="3"><textarea rows="5" name="remark" cols="30">${remark}</textarea>
		</td>
	</tr>
</table>
<div class="type-button"><input type="submit" class="submit"
	value="提交" />&nbsp;
&nbsp; <input type="button" value="返回" class="reset"
	onclick="history.back()" /></div>
</form>
<c:if test="${!empty id}">
	<form action="${ctx}/asset/book/bksn!save.action" method="post"
		id="inputForm" class="yform">
	<div id="caption">
	<h5>图书登记编号</h5>
	</div>
	<table class="noborder" border="0" id="tabtest">
		<c:forEach items="${bksnList}" var="bksn" varStatus="status">
		<tr id="snTr${status.count}">
			<td>图书ISBN编号</td>
			<td><input id="bkSn${status.count}" name="bookSN" type="text" value="${bksn.bookSN}"/>
				<input id="bkid${status.count}" name="id" type="hidden" value="${bksn.id}"/>
				<input id="bookinfoId${status.count}" name="bookinfoId'${status.count}'"  type="hidden"  value="${id}" />
				<input id="status${status.count}" name="status" type="hidden" value="${bksn.status}" />
			</td>
			<td colspan="2">
			<input id="savebksn" type="button" class="submit" 
			value="保存" onclick="saveBkSn('${status.count}');"/>
			<input align="bottom" type="button" class="reset" value="删除" onclick="deleteBkSn('${status.count}');" /></td>
		</tr>
		</c:forEach>
	</table>
	<div class="type-button">&nbsp;<input type="button" class="submit" value="编号 " onclick="doAppend()" />
		&nbsp;</div>
	</form>
</c:if>
</body>
</html>
